package com.clementheliou.cheliou.web.util.cookie.fest.asserter;

import static org.fest.assertions.api.Assertions.assertThat;

import javax.servlet.http.Cookie;

import org.fest.assertions.api.AbstractAssert;

import com.clementheliou.cheliou.web.core.fest.assertions.CHeliouWebAssertions;

/**
 * FEST asserter used to make test code about {@link Cookie} instances more readable. It should only
 * be used through the static factory that can be found into the project assertions class (
 * {@link CHeliouWebAssertions}).
 * 
 * @author Clément HELIOU (clement.heliou@gmail.com)
 * @see {@link AbstractAssert};
 * @see {@link Cookie};
 * @see {@link CHeliouWebAssertions}.
 * @since 1.0
 */
public class CookieAsserter extends AbstractAssert<CookieAsserter, Cookie> {

	/**
	 * Constructor from the {@link Cookie} instance to be asserted.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @param actual the {@link Cookie} instance to be asserted.
	 * @since 1.0
	 */
	public CookieAsserter(final Cookie actual) {
		super(actual, CookieAsserter.class);
	}

	/**
	 * Asserts that current {@link Cookie} has the expected max age.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @param expectedMaxAge the expected max age value.
	 * @return the asserter instance after this assertion.
	 * @since 1.0
	 */
	public CookieAsserter hasMaxAge(final int expectedMaxAge) {
		isNotNull();
		assertThat(actual.getMaxAge()).isEqualTo(expectedMaxAge);
		return this;
	}

	/**
	 * Asserts tha current {@link Cookie} has the expected name.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @param expectedName the expected name value.
	 * @return the asserter instance after this assertion.
	 * @since 1.0
	 */
	public CookieAsserter hasName(final String expectedName) {
		isNotNull();
		assertThat(actual.getName()).isEqualTo(expectedName);
		return this;
	}

	/**
	 * Asserts that current {@link Cookie} has the expected path.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @param expectedPath the expected path value.
	 * @return the asserter instance after this assertion.
	 * @since 1.0
	 */
	public CookieAsserter hasPath(final String expectedPath) {
		isNotNull();
		assertThat(actual.getPath()).isEqualTo(expectedPath);
		return this;
	}

	/**
	 * Asserts that current {@link Cookie} has the expected value.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @param expectedValue the expected value.
	 * @return the asserter instance after this assertion.
	 * @since 1.0
	 */
	public CookieAsserter hasValue(final String expectedValue) {
		isNotNull();
		assertThat(actual.getValue()).isEqualTo(expectedValue);
		return this;
	}
}
